<template>
  <div style="">
    <Header :left="true" leftText="返回" title="异常单据填写"> </Header>
    <NoticeBar
      color="#1989fa"
      background="#ecf9ff"
      style="margin-top: 5px; font-size: 15px; font-weight: bold"
      left-icon="description"
      >单据填写信息</NoticeBar
    >
    <van-form :style="autoHeight" @submit="onSubmit">
      <van-field
        class="formstyle"
        required
        readonly
        clickable
        label="选择延误原因"
        :value="value"
        placeholder="选择原因"
        @click="showPicker = true"
      />
      <van-popup v-model="showPicker" round position="bottom">
        <van-picker
          show-toolbar
          :columns="columns"
          @cancel="showPicker = false"
          @confirm="onConfirm"
        />
      </van-popup>

      <van-field
        v-show="reasonbool"
        class="formstyle"
        v-model="reasonvalue"
        label="请输入原因"
        placeholder="原因输入"
      />
      <van-field class="formstyle" name="stepper" label="延误周期选择(10分钟)">
        <template #input>
          <van-stepper v-model="stepper" />
        </template>
      </van-field>

      <div style="margin: 16px">
        <van-button round color="#138087" block type="info" @click="submitsure"
          >确定</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import {
  Col,
  Row,
  Form,
  Cell,
  Icon,
  Field,
  NumberKeyboard,
  Image as VanImage,
  Picker,
  popup,
  SubmitBar,
  Button,
  Loading,
  Overlay,
  Dialog,
  Toast,
  NoticeBar,
  Tag,
  DatetimePicker,
  ImagePreview,
  CellGroup,
  Uploader,
  Cascader,
  Calendar,
  RadioGroup,
  Radio,
  Divider,
  Stepper,
  AddressList,
  Checkbox,
  CheckboxGroup,
} from "vant";
import { _httpClient } from "@/libs/api";
import "vue-easytable/libs/themes-base/index.css";
import { VTable } from "vue-easytable";
import { getToken, getBaseApiFrefix } from "@/libs/auth";
import Header from "@/components/header.vue";
import { storage } from "@/libs/utils";

Vue.use(Form);
Vue.use(Field);
Vue.use(Overlay);
Vue.use(Loading);
Vue.use(Picker);
Vue.use(popup);
Vue.use(SubmitBar);
Vue.use(VanImage);
Vue.use(DatetimePicker);
Vue.use(Cascader);
Vue.use(Calendar);
Vue.use(Cell);
Vue.use(RadioGroup);
Vue.use(Radio);
Vue.use(Divider);
Vue.use(Stepper);
Vue.use(Button);
Vue.use(AddressList);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Col);
Vue.use(Row);

export default {
  name: "abnormaldocuments",
  components: {
    Form,
    Row,
    Col,
    Button,
    Header,
    Form,
    Cell,
    Icon,
    Field,
    NumberKeyboard,
    Dialog,
    Toast,
    NoticeBar,
    Row,
    Tag,
    popup,
    DatetimePicker,
    ImagePreview,
    CellGroup,
    Uploader,
    Col,
    Calendar,
    Cascader,
    Picker,
    RadioGroup,
    Radio,
    Divider,
    Stepper,
    VTable,
    AddressList,
    Checkbox,
    CheckboxGroup,
  },
  data() {
    return {
      id: "",
      type: "",
      reasonbool: false,
      reasonvalue: "",
      value: "",
      showPicker: false,
      columns: [
        "车辆不足",
        "有车无驾驶员",
        "出口检临时扣货",
        "仓库未及时集货",
        "账实不符库存不足",
        "生产延误交货不足",
        "客户压货车辆不能及时返回",
        "其他",
      ],
      stepper: 1,
      form: {},
      valuematerial: "",
      columnsmaterial: ["物料一", "物料二", "物料三", "物料四", "物料五"],
      showPickermaterial: false,
      user: [],
      valuedatetime: "",
      showPickerdatetime: false,
    };
  },

  created: function () {
    this.id = api.pageParam.id;
    this.type = api.pageParam.type;
    //console.log("Hello");
    this.user = JSON.parse(storage.get("user"));
  },
  mounted() {},

  methods: {
    async submitsure() {
      let _this = this;
      var delaytimestring = (_this.stepper * 10).toString();
      var delayreasonstring = _this.value + " " + _this.reasonvalue;
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() +
            "/app/logistics/ProductionDeliveryPlan/delaysinprocessingsuper",
          {
            body: {
              id: _this.id,
              factoryid: _this.user.site,
              delaytime: delaytimestring,
              type: _this.type,
              delayreason: delayreasonstring,
            },
          }
        );
        if (res.code === 200) {
          if (_this.type == "1") {
            api.openWin({
              name: "logistics-shippingconfirmation",
              url: "./logistics-shippingconfirmation.html",
              reload: true,
            });
          } else if (_this.type == "2") {
            api.openWin({
              name: "logistics-departureconfirmation",
              url: "./logistics-departureconfirmation.html",
              reload: true,
            });
          } else if (_this.type == "3") {
            api.openWin({
              name: "logistics-vehiclearrivesconfirm",
              url: "./logistics-vehiclearrivesconfirm.html",
              reload: true,
            });
          }
        } else {
          Toast.fail(res.msg);
        }
      } catch (e) {
        alert(JSON.stringify(e));
        Toast.fail(JSON.stringify(e));
      }
    },
    onConfirm(value) {
      this.value = value;
      this.showPicker = false;
      if (value == "其他") {
        this.reasonbool = true;
      } else {
        this.reasonbool = false;
      }
    },
    //打开扫描
    showScanner() {
      let _this = this;
      if (
        api.deviceName.toLowerCase() == "huawei" ||
        api.deviceName.toLowerCase() == "honor"
      ) {
        var QRScan = api.require("QRScan");
        QRScan.customizedScanner(
          {
            rect: {
              x: 15, //（可选项）数字类型；模块左上角的 x 坐标（相对于所属的 Window 或 Frame）；默认：0
              y: 0, //（可选项）数字类型；模块左上角的 y 坐标（相对于所属的 Window 或 Frame）；默认：0
              w: 320, //（可选项）数字类型；模块的宽度；支持设置'auto'；默认：所属的 Window 或 Frame 的宽度
              h: 480, //（可选项）数字类型；模块的高度；支持设置'auto'；默认：所属的 Window 或 Frame 的高度
            },
            rectOfInterest: {
              x: 64, //（可选项）数字类型；扫码识别区域左上角的 x 坐标（相对于扫码区rect）；默认：0
              y: 65, //（可选项）数字类型；扫码识别区域左上角的 y 坐标（相对于扫码区rect）；默认：0
              w: 250, //（可选项）数字类型；扫码识别区域的宽度；默认：扫码区rect的宽度
              h: 250, //（可选项）数字类型；扫码识别区域的高度；默认：扫码区rect的高度
            },
            //tipString:'放入框内扫码',
            maskColor: "rgba(0,0,0,0.5)",
            scanLine: {
              color: "#00FF00",
              thickness: 2,
            },
            marginB: 30,
            formatType: "ALL",
          },
          function (ret) {
            if (ret) {

            }
          }
        );
              //  QRScan.closeCustomizedScanner();
      } else {
        var FNScanner = _this.$ac.require("FNScanner");
        FNScanner.openScanner(
          {
            autorotation: true,
          },
          function (ret, err) {
            if (ret) {
              if (ret.eventType == "success" && ret.content != "") {
                //_this.queryEquip({ body: { equipCode: ret.content, siteKey: _this.user.site } })
              }
            } else {
              alert(JSON.stringify(err));
            }
          }
        );
      }
    },
  },
};
</script>

<style>
body {
  background-color: white;
}

.table-title-class {
  background-color: #304156;
  color: #fff;
}

.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.buttongroup {
  float: right;
  margin-right: 10px;
  margin-top: 10px;
  margin-bottom: 20px;
}

.container.dwo {
  display: flex;
  justify-content: center;
  align-items: center;
}

.buttonLeft {
  position: fixed;
  bottom: 8px;
  float: left;
  width: 49%;
}

.formstyle {
  margin-top: 8px;
  font-size: 15px;
  font-weight: bold;
  display: flex;
  align-items: center;
}

.radioteam {
  display: flex;
  align-items: center;
  padding-left: 13px;
  margin-top: 10px;
  margin-left: 34px;
  margin-bottom: 10px;
}

.buttonRight {
  position: fixed;
  bottom: 8px;
  float: right;
  left: 51%;
  width: 49%;
  background-color: #f22028;
  border-color: #f22028;
}

.textScroll {
  display: inline-block;
  position: fixed;
  top: 50%;
  bottom: 3rem;
  overflow: scroll;
  right: 10px;
  width: 100%;
  z-index: 1;
}

.message {
  font-size: 15px;
  margin-top: 5px;
  margin-left: -10px;
  font-weight: bold;
}

.mg5 {
  margin-right: 5px;
}

.tag_margin {
  margin: 2px 5px;
}

.card_under {
  height: 100%;
  width: 100%;
  margin: auto;
  background: #ffffff;
  border-radius: 25px;
  box-shadow: 0 0px 0px rgba(0, 0, 0, 0.3);
}

.card_icon {
  text-align: center;
  /* position: absolute; */
  height: 8rem;
  width: 80%;
  margin: 12% 10%;
  background: rgba(35, 180, 237, 1);
  border-radius: 25px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
}

.text {
  font-size: 18px;
  color: #4e4a67;
  margin: 8px auto auto 20px;
  line-height: 1.5rem;
  text-align: justify;
  font-weight: 600;
}

.text_small {
  font-size: 16px;
  color: red;
  margin: 8px auto auto 20px;
  line-height: 1.5rem;
  text-align: justify;
  font-weight: 700;
}

.text_scan {
  font-size: 16px;
  color: #4e4a67;
  margin: auto auto auto 20px;
  line-height: 1.5em;
  text-align: justify;
}

.divStyle {
  margin-left: 3px;
  margin-right: 3px;
}
</style>
